package net.my.msn.dao.impl;

import java.util.List;

import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import net.my.msn.dao.JpaImplTemplateDAO;
import net.my.msn.dao.VoiceDAO;
import net.my.msn.domain.Voice;

@Repository
public class VoiceDAOImpl extends JpaImplTemplateDAO<Voice, Long> implements
		VoiceDAO {

	public VoiceDAOImpl() {
		super(Voice.class);
	}

	public int isUserVotedForThisMessage(Long m_id, Long u_id) {
		Query q = em.createNamedQuery("isUserVotedForThisMessage")
				.setParameter("m_id", m_id).setParameter("u_id", u_id);
		Long l = (Long) q.getSingleResult();
		return l.intValue();

	}

	public int findVoiceByMessageId(Long m_id) {
		Query q = em.createNamedQuery("findVoiceByMessageId").setParameter("m_id",
				m_id);
		Long l = (Long) q.getSingleResult();
		return l.intValue();

	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Voice> find() {
		Query q = em.createNamedQuery("findAllVoices");
		return q.getResultList();
	}
}